$(document).ready(function(){            
	$("#sTeachersInfo").jqGrid({                
		url:global_url+global_urijs+'schoolteachers_searchSchoolTeacherList'+global_suffix+"?sid="+global_sid,                
		datatype:"json",                
		mtype:'GET', 
		height:'300',
		width:'770',
		colNames:['姓名','账号','性别','职务','所在班级','所管理班级','学校管理员','操作','isadmin','tid'],                
		colModel:[                    
		{name:'tname',index:'tname',width:100,align:'center'},                    
		{name:'account',index:'account',width:100,align:'center'},         
		{name:'sex',index:'sex',width:100,align:'center', sortable:false},
		{name:'gname',index:'gname',width:80,align:'center', sortable:false},
		{name:'classNams_in',index:'classNams_in',width:200,align:'center', sortable:false},
		{name:'className_manage',index:'className_manage',width:200,align:'center', sortable:false},
		{name:'upadmin',index:'upadmin',width:120,align:'center', sortable:false},
		{name:'option',index:'option',width:100,align:'center', sortable:false},
		{name:'isadmin',index:'isadmin',hidden:true},
		{name:'tid',index:'tid',hidden:true}    
		],

		//autowidth:true,
		jsonReader: {
			root:"schoolTeacherList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#sTeachersPage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'tname',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '教师信息',
		gridComplete:function(){
			var ids=jQuery("#sTeachersInfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];   
				var admin = jQuery("#sTeachersInfo").jqGrid('getRowData', id).isadmin;
				if(admin==1){
					adm = "<a href='javascript:;' class='jqtrow' onclick='chTel(" + id + ",0)'>取消管理员</a>";
				}else{
					adm = "<a href='javascript:;' class='jqtrow' onclick='chTel(" + id + ",1)'>设为管理员</a>";
				}
				del = "<a href='javascript:;' class='jqtrow' onclick='delTel(" + id + ")'>删除</a>"; 
				ma = "<a href='javascript:;' class='jqtrow' onclick='upTel(" + id + ")'>管理</a>"; 
				jQuery("#sTeachersInfo").jqGrid('setRowData', ids[i], { upadmin:adm,option: del + " " + ma });
			}
		}
	}).navGrid("#sTeachersPage", { edit: false, add: false, del: false, search: false });
});

function delTel(id){
	 $(function() {$( "#compPrompt" ).dialog({
		modal: true,
		resizable: false,
		buttons: {
			"删除": function() {
				var funadd = function(data1){
					if(1==data1.s){
						 $().message("删除成功!");
						 $("#sTeachersInfo").trigger("reloadGrid");
						 $("#compPrompt").dialog( "close" );
					}else{
						 $().message("删除失败!");
					}
				};
				exeAjax(ajaxUrl(global_url+global_urijs+'schoolteachers_deleteSchoolTeacher'+global_suffix), funadd, {"tid" :jQuery("#sTeachersInfo").jqGrid('getRowData', id).tid});
			},"取消": function() {
				$( this ).dialog( "close" );
			}
		}
		});
	});
}

function chTel(id,isadmin){
	var funadd = function(data1){
		$("#sTeachersInfo").trigger("reloadGrid");
	};
	exeAjax(ajaxUrl(global_url+global_urijs+'schoolteachers_updateSchoolTeacherAdmin'+global_suffix), funadd, {
		"tid" :jQuery("#sTeachersInfo").jqGrid('getRowData', id).tid,"isadmin_school":isadmin});

}

function showCtInviteInfo(){
	//教师邀请记录
	$("#ctInviteInfo").jqGrid({                
		url:global_url+global_urijs+'schoolteachers_searchInviteTeacherList'+global_suffix+"?sid="+global_sid,                
		datatype:"json",                
		mtype:'GET', 
		height:'250',
		width:'740',
		colNames:['姓名','班级','职务','手机号码','添加日期','itid'],                
		colModel:[                    
		{name:'tname',index:'tname',width:120,align:'center'}, 
		{name:'name_class',index:'name_class',width:120,align:'center'},  
		{name:'gname',index:'gname',width:120,align:'center'},                    
		{name:'phone',index:'phone',width:120, sortable:false,align:'center'},
		{name:'ctime_str',index:'ctime_str',width:120,align:'center', sortable:false},
		{name:'itid',index:'itid',hidden:true}    
		],
		//autowidth:true,
		jsonReader: {
			root:"inviteTeacherList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#ctInvitePage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'ctime_str',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '',
		gridComplete:function(){
			var ids=jQuery("#ctInviteInfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];   
				
				jQuery("#ctInviteInfo").jqGrid('setRowData', ids[i]);
			}
		}
	}).navGrid("#ctInvitePage", { edit: false, add: false, del: false, search: false });
}







